<?php

use common\widgets\ButtonDropdown;
use common\widgets\GridView;
use common\widgets\pages\CustomTabs as Tabs;
use yii\helpers\Html;

/* @var $this yii\web\View */
/* @var $searchModel common\components\ActiveRecord */
/* @var $dataProvider yii\data\ActiveDataProvider */
/* @var array $gridViewActionConfig */
/* @var array $gridViewActionButtons */

$model = $searchModel;

$this->title = isset($pageTitle) ? $pageTitle :
    method_exists($model, "classLabelName") ? $model->classLabelName() : $model->className();
$this->params['subtitle'] = '列表';
$this->params['tabId'] = md5(microtime(true));
$this->params['createTabId'] = "{$this->params['tabId']}-create";
$this->params['breadcrumbs'] = [
    $this->title
];
$this->params['breadcrumbs'][] = $this->title . ' ' . $this->params['subtitle'];

//配置表格右上操作按钮
$gridViewButtons = "";
if (isset($gridViewActionButtons)) {
    $gridViewActionButtonDefaultConfig = [
        'label' => '操作',
        'options' => ['class' => "btn-default"],
        'dropdown' => [
            'items' => $gridViewActionButtons
                //['label' => 'DropdownA', 'url' => '/'],
                //['content' => 'DropdownA'],
            ,
        ],
    ];
    if (isset($gridViewActionConfig)) {
        $gridViewActionButtonDefaultConfig = \yii\helpers\ArrayHelper::merge($gridViewActionButtonDefaultConfig, $gridViewActionConfig);
    }
    $gridViewButtons = ButtonDropdown::widget($gridViewActionButtonDefaultConfig);
}


$gridViewConfig = [
    'id' => md5($searchModel->className()),
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'panel' => [
        'heading' => ""
    ],
    'pjax' => false,
    'toolbar' => [
        [
            'content' =>
                Html::a('<i class="glyphicon glyphicon-plus"></i>', ['create'], ['data-pjax' => 0, 'type' => 'button', 'title' => Yii::t('kvgrid', 'Add'), 'class' => 'btn btn-success']) . ' ' .
//                Html::button('<i class="glyphicon glyphicon-plus"></i>', ['type' => 'button', 'title' => Yii::t('kvgrid', 'Add'), 'class' => 'btn btn-success', 'onclick' => "$('a[href=\"#{$this->params['createTabId']}\"]').tab('show')"]) . ' ' .
                Html::a('<i class="glyphicon glyphicon-repeat"></i>', ['index'], ['data-pjax' => 0, 'class' => 'btn btn-default', 'title' => Yii::t('kvgrid', 'Reset Grid')]) .
                $gridViewButtons
        ],
        '{export}',
        '{toggleData}'
    ],
    'columns' => $model->gridViewColumns(),
];



$grid = GridView::widget($gridViewConfig);


$tabContent = $grid;
$tabsConfig['title'] = $this->title;
$tabsConfig['id'] = $this->params['tabId'];
$tabsConfig["items"][] = [
    "label" => $this->params['subtitle'],
    "content" => $tabContent,
];

//$tabsConfig["items"][] = [
//    "label" => "Create",
//    'options' => ['id' => "{$this->params['createTabId']}"],
//    "content" => $this->render('_form', ['model' => $model,'method'=>"create"]),
//];

$content = Tabs::widget($tabsConfig);

echo Html::tag("div",
    Html::tag("div", $content, ['class' => "col-xs-12 " . \yii\helpers\Inflector::slug($model->className()) . "grid-view"])
    , ['class' => "row"]);

